package com.gaara.ddp;

import java.util.Vector;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;

public class Bomb {

	Bitmap bitmap[];
	int height,witdh;
	Vector<Point> vector = new Vector<Point>();

	public Bomb(Bitmap[] bitmap, int height, int witdh) {
		this.bitmap = bitmap;
		this.height = height;
		this.witdh = witdh;
	}
	
	public void add(int x, int y, int type){
		vector.addElement(new Point(x, y, type));
	}
	
	public void move(){
		for(Point point:vector){
			if(point.translating>bitmap[point.type].getWidth()/2){
				vector.remove(point);
			}
		}
		vector.trimToSize();
	}
	
	public void paint(Canvas canvas,Paint paint){
		canvas.save();
		canvas.clipRect(0, 0, witdh,height);
		for(Point point:vector){
			int translating = point.translating;
			Bitmap myBit = bitmap[point.type];
			canvas.drawBitmap(bitmap[point.type], null, new Rect(point.x+translating, point.y+translating,myBit.getWidth()-translating,myBit.getHeight()-translating), paint);
			point.translating +=2;
		}
		canvas.restore();
	}
	
	class Point{
		int x,y,type,translating;

		public Point(int x, int y, int type) {
			this.x = x;
			this.y = y;
			this.type = type;
		}
		
	}
}
